<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 200px;
            height: 200px;
            background-color: red;
        }
        .active{
            background-color: green;
        }
    </style>
</head>
<body>
    <div id="app">
        <!-- <button v-on:click="handleChange">改变颜色</button> -->
        <!-- v-bind 可以绑定标签中的所有属性, 例如img标签src alt a标签的helf title id class -->
        <!-- <img v-bind:src="imgSrc" v-bind:alt="imgAlt"> -->
        <!-- <div class="box" v-bind:class='{active:isActive}'></div> -->


        <!-- 简便写法 v-on 可以写成@  v-bind可以写成: -->
        <button @click="handleChange">改变颜色</button>
        <button @mouseenter="handleEnter" @mouseleave="handleLeave">鼠标放上改变颜色</button>
        <!-- v-bind 可以绑定标签中的所有属性, 例如img标签src alt a标签的helf title id class -->
        <img :src="imgSrc" :alt="imgAlt">
        <div class="box" :class='{active:isActive}'></div>

    </div>
    <script src="./vue.js"></script>
    <script>
        // 数据驱动视图 设计模式 MVVM Model View ViewModel

        // v-bind 和 v-on的简便写法 v-bind可以直接写成: 冒号   v-on可以写成@
        // 绑定标签
        new Vue({
            el: '#app',
            data() {
                return {
                    imgSrc:'./4.png',
                    imgAlt: '猫',
                    isActive: true
                }
            },
            methods: {
                handleChange() {
                    this.isActive = !this.isActive;
                },
                handleEnter() {
                    this.isActive = false;
                },
                handleLeave() {
                    this.isActive = true;
                }
            },
        });
    </script>
</body>
</html>